<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;

/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var yiike\goods\model\GoodsSearch $searchModel
 */

$this->title = Yii::t('models', '商品列表');
$this->params['breadcrumbs'][] = $this->title;

if (isset($actionColumnTemplates)) {
    $actionColumnTemplate = implode(' ', $actionColumnTemplates);
    $actionColumnTemplateString = $actionColumnTemplate;
} else {
    Yii::$app->view->params['pageButtons'] = Html::a('<span class="glyphicon glyphicon-plus"></span> ' . 'New', ['create'], ['class' => 'btn btn-success']);
    $actionColumnTemplateString = " {update} {delete}";
}
$actionColumnTemplateString = '<div class="action-buttons">'.$actionColumnTemplateString.'</div>';

?>
<div class="box box-info giiant-crud goods-index">
    <div class="box-header with-border">
        <div class="box-title">
            <?= Yii::t('models', $store->title) ?>
        </div>
    </div>
    <div class="box-body">
        <?php
        //             echo $this->render('_search', ['model' =>$searchModel]);
        ?>


        <?php \yii\widgets\Pjax::begin(['id'=>'pjax-main', 'enableReplaceState'=> false, 'linkSelector'=>'#pjax-main ul.pagination a, th a', 'clientOptions' => ['pjax:success'=>'function(){alert("yo")}']]) ?>


        <div class="clearfix crud-navigation">
            <div class="pull-left">
                <?= Html::a('<span class="glyphicon glyphicon-plus"></span> ' . '添加', ['create','store_id'=>$store->id], ['class' => 'btn btn-success']) ?>
            </div>

            <div class="pull-right">


                <?=
                \yii\bootstrap\ButtonDropdown::widget(
                    [
                        'id' => 'giiant-relations',
                        'encodeLabel' => false,
                        'label' => '<span class="glyphicon glyphicon-paperclip"></span> ' . 'Relations',
                        'dropdown' => [
                            'options' => [
                                'class' => 'dropdown-menu-right'
                            ],
                            'encodeLabels' => false,
                            'items' => [
                                [
                                    'url' => ['goods-category/index'],
                                    'label' => '<i class="glyphicon glyphicon-arrow-left"></i> ' . Yii::t('models', 'Goods Category'),
                                ],
                                [
                                    'url' => ['stores/index'],
                                    'label' => '<i class="glyphicon glyphicon-arrow-left"></i> ' . Yii::t('models', 'Stores'),
                                ],

                            ]
                        ],
                        'options' => [
                            'class' => 'btn-default'
                        ]
                    ]
                );
                ?>
            </div>
        </div>

        <hr />

        <div class="table-responsive">
            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'pager' => [
                    'class' => yii\widgets\LinkPager::className(),
                    'firstPageLabel' => '首页',
                    'lastPageLabel' => '末页',
                ],
                'filterModel' => $searchModel,
                'tableOptions' => ['class' => 'table table-striped table-bordered table-hover'],
                'headerRowOptions' => ['class'=>'x'],
                'columns' => [
                    [
                        'class' => 'yii\grid\ActionColumn',
                        'template' => $actionColumnTemplateString,
                        'buttons' => [
                            'view' => function ($url, $model, $key) {
                                $options = [
                                    'title' => Yii::t('cruds', 'View'),
                                    'aria-label' => Yii::t('cruds', 'View'),
                                    'data-pjax' => '0',
                                ];
                                return Html::a('<span class="glyphicon glyphicon-file"></span>', $url, $options);
                            },
                            'update' => function ($url, $model, $key) {
                                $options = [
                                    'title' => Yii::t('cruds', '编辑'),
                                    'aria-label' => Yii::t('cruds', '编辑'),
                                    'data-pjax' => '0',
                                ];
                                $url = Url::toRoute(['goods/update','id'=>$model->id,'store_id'=>$model->store_id]);
                                return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);
                            }
                        ],
                        'urlCreator' => function($action, $model, $key, $index) {
                            // using the column name as key, not mapping to 'id' like the standard generator
                            $params = is_array($key) ? $key : [$model->primaryKey()[0] => (string) $key];
                            $params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id . '/' . $action : $action;
                            return Url::toRoute($params);
                        },
                        'contentOptions' => ['nowrap'=>'nowrap']
                    ],
                    'id',
                    'orderby',
                    'title',
                    'stock',
                    'logo'=>[
                        'label' => '主图',
                        'format' => [
                            'image',
                            [
                                'height' =>100,
                                'width' => 100
                            ]
                        ],
                        'value' => function($model){
                            return $model->logo;
                        }
                    ],
                    'cost_price',
                    'orig_price',
                    'price',
                    [
                        'label'=>'状态',
                        // 'format'=>'raw',
                        'attribute'=>'status',
                        'content'=>function($model){
                            if($model->status==1){
                                return Html::label('已上架','',['class'=>'label label-success']);
                            }else{
                                return Html::label('已下架','',['class'=>'label label-warning']);
                            }
                        },
                        'filter' => [0=>'已下架',1=>'已上架'],//重点在这里，传入一个数组，会下拉框显示
                    ],
                    'created_at:datetime',
                    /*'content:ntext',*/
                    /*'quan_rule',*/
                    /*'type',*/
                    /*'top',*/
                    /*'orderby',*/
                    /*'sold',*/
                    /*'full_num_shipping',*/
                    /*'invoice',*/
                    /*'status',*/
                    /*'sale_time_start:datetime',*/
                    /*'sale_time_end:datetime',*/
                    /*'hide_search',*/
                    /*'no_return',*/
                    /*'weight',*/

                    /*'stock_rule',*/
                    /*'is_spec',*/
                    /*'max_buy',*/
                    /*'min_buy',*/
                    /*'give_credit1',*/
                    /*'no_shipping:ntext',*/
                    /*'property:ntext',*/


                    /*'full_money_shipping',*/
                    /*'shipping_fee',*/
                    /*'commision',*/
                    /*'goods_sn',*/
                    /*'sub_title',*/
                    /*'short_title',*/
                    /*'keyword',*/
                    /*'tag',*/
                    /*'location_p',*/
                    /*'location_c',*/
                    /*'share_image',*/
                    /*'share_title',*/
                    /*'share_content',*/
                ],
            ]); ?>
        </div>
        <?php \yii\widgets\Pjax::end() ?>
    </div>
</div>




